import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/** note: submenu only apppear when children.length>=1
*   detail see  https://panjiachen.github.io/vue-element-admin-site/#/router-and-nav?id=sidebar
**/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  { path: '/login', component: _import('login/index'), hidden: true },
  { path: '/login_test', component: _import('login/test'), hidden: true },
  { path: '/authredirect', component: _import('login/authredirect'), hidden: true },
  { path: '/404', component: _import('errorPage/404'), hidden: true },
  { path: '/401', component: _import('errorPage/401'), hidden: true },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [{
      path: 'dashboard',
      component: _import('dashboard/index'),
      name: 'dashboard',
      meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
    }]
  }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/byOrder',
    component: Layout,
    meta: {
      title: 'order',
      icon: 'component',
      roles: ['admin'],
      hash: 'ba7d0e4ac4febe6a'
    },
    children: [
      { path: 'create', name: 'create',
        component: _import('byOrder/create'),
        meta: { title: 'create', icon: 'component', roles: ['admin'], hash: 'eac69cc271b8bd09' }},
      { path: 'order', name: 'order',
        component: _import('byOrder/order'),
        meta: { title: 'order', icon: 'component', roles: ['admin'], hash: 'ba7d0e4ac4febe6a' }},
      { path: 'breakBill', name: 'breakBill',
        component: _import('byOrder/breakBill'),
        meta: { title: 'breakBill', icon: 'component', roles: ['admin'], hash: 'a91d683e0fbc39a1' }}
    ]
  },
  {
    path: '/byTransport',
    component: Layout,
    meta: {
      title: 'transport',
      icon: 'component',
      roles: ['admin'],
      hash: 'f57a86835d72582c'
    },
    children: [
      { path: 'loadCar', name: 'loadCar',
        component: _import('byTransport/loadCar'),
        meta: { title: 'loadCar', icon: 'component', roles: ['admin'], hash: '432d153b2173c2f4' }},
      { path: 'transportBill', name: 'transportBill',
        component: _import('byTransport/transportBill'),
        meta: { title: 'transportSearch', icon: 'component', roles: ['admin'], hash: 'fe1870dedc47d84f' }}
    ]
  },

  {
    path: '/wareHouse',
    component: Layout,
    meta: {
      title: 'warehouse',
      icon: 'component',
      roles: ['admin'],
      hash: 'c15d3a6c3654426a'
    },
    children: [
      { path: 'production', name: 'production',
        component: _import('byWareHouse/production'),
        meta: { title: 'production', icon: 'component', roles: ['admin'], hash: 'c15d3a6c3654426a' }}
    ]
  },

  {
    path: '/salary',
    component: Layout,
    meta: {
      title: 'salary',
      icon: 'component',
      roles: ['admin'],
      hash: 'f1f4b88c97d9f90d'
    },
    children: [
      { path: 'workerSalary', name: 'workerSalary',
        component: _import('bySalary/workerSalary'),
        meta: { title: 'workerSalary', icon: 'component', roles: ['admin'], hash: 'ec925d115f944389' }},
      { path: 'productionSinglePrice', name: 'productionSinglePrice',
        component: _import('bySalary/productionSinglePrice'),
        meta: { title: 'productionSinglePrice', icon: 'component', roles: ['admin'], hash: '67f5b29ae4395f4d' }}
    ]
  },

  {
    path: '/baseData',
    component: Layout,
    meta: {
      title: 'baseData',
      icon: 'component',
      roles: ['admin'],
      hash: '95eea6ee304dcff6'
    },
    children: [
      { path: 'productionBaseData', name: 'productionBaseData',
        component: _import('baseData/productionBaseData'),
        meta: { title: 'productionBaseData', icon: 'component', roles: ['admin'], hash: '0c0c3dd94827ffcb' }},
      { path: 'standardPriceData', name: 'standardPriceData',
        component: _import('baseData/standardPriceData'),
        meta: { title: 'standardPriceData', icon: 'component', roles: ['admin'], hash: 'b2ab858da9fb0b0f' }},
      { path: 'customerData', name: 'customerData',
        component: _import('baseData/customerData'),
        meta: { title: 'customerData', icon: 'component', roles: ['admin'], hash: 'ef4b6a459caecaf0' }},
      { path: 'freightData', name: 'freightData',
        component: _import('baseData/freightData'),
        meta: { title: 'freightData', icon: 'component', roles: ['admin'], hash: 'f822cfde74208621' }},
      { path: 'rawMaterialData', name: 'rawMaterialData',
        component: _import('baseData/rawMaterialData'),
        meta: { title: 'rawMaterialData', icon: 'component', roles: ['admin'], hash: '652a2dd61ea6ab09' }},
      { path: 'provinceData', name: 'provinceData',
        component: _import('baseData/provinceData'),
        meta: { title: 'provinceData', icon: 'component', roles: ['admin'], hash: '7139d36f55039b46' }}
    ]
  },
  {
    path: '/user',
    component: Layout,
    meta: {
      title: 'user',
      icon: 'component',
      roles: ['admin'],
      hash: '3eb68bae06043db4'
    },
    children: [
      { path: 'user', name: 'user',
        component: _import('byUser/userManagement'),
        meta: { title: 'user', icon: 'component', roles: ['admin'], hash: '3eb68bae06043db4' }}
    ]
  },

  {
    path: '/icon',
    component: Layout,
    children: [{
      path: 'index',
      component: _import('svg-icons/index'),
      name: 'icons',
      meta: { title: 'icons', icon: 'icon', noCache: true, hash: '' }
    }]
  }
]
